<template>
  <div class="c-layout">
    <!-- 顶部导航栏 -->
    <header class="layout-header">
      <div class="header-content">
        <div class="brand">
          <img 
            src="@/assets/logo.png" 
            class="logo"
          >
          <span class="title">康运集团</span>
        </div>
 
        <!-- 顶部导航菜单 -->
        <el-menu 
          class="header-nav"
          mode="horizontal"
          :default-active="$route.path" 
          router 
        >
          <el-menu-item index="/c/purchase">
            <el-icon>
              <Goods />
            </el-icon>
            <span>采购指南</span>
          </el-menu-item>
          <el-menu-item index="/c/ordercreate">
            <el-icon>
              <DocumentAdd />
            </el-icon>
            <span>下单</span>
          </el-menu-item>
          <el-menu-item index="/c/company">
            <el-icon>
              <OfficeBuilding />
            </el-icon>
            <span>企业介绍</span>
          </el-menu-item>
        </el-menu>
 
        <div class="user-info">
          <el-dropdown>
            <span class="user-name">
              <el-icon>
                <User />
              </el-icon>
              您好，{{ userName }}
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="$router.push('/c/account')"> 
                  个人中心 
                </el-dropdown-item>
                <el-dropdown-item @click="$router.push('/clogin')"> 
                  退出登录 
                </el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </div>
    </header>
 
    <!-- 主内容区 - 始终居中 -->
    <div class="content-wrapper">
      <main class="layout-main">
        <router-view />
      </main>
    </div>
  </div>
</template>
 
<script>
import { ref ,onMounted} from "vue";
import { useRoute } from "vue-router";
import { Goods, DocumentAdd, User, OfficeBuilding } from "@element-plus/icons-vue";
import authStore from "@/model/authstore"; 
export default {
  components: { Goods, DocumentAdd, User, OfficeBuilding },
  setup() {
    const route = useRoute();
    const userName = ref("");
 
    onMounted(() => {
      // 从统一存储获取用户信息 
      const authData = authStore.get('auth'); 
      if (authData?.user?.name) {
        userName.value  = authData.user.name; 
      }
    });
 
    return {
      userName 
    };
  }
};
</script>
 
<style scoped lang="scss">
.c-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f5f7fa;
}
 
/* 头部样式 - 保持原有布局 */
.layout-header {
  height: 60px;
  background: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: -60px;
  z-index: 10;
  width: 100%;
}
 
.header-content {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}
 
.brand {
  display: flex;
  align-items: center;
 
  .logo {
    width: 28px;
    height: 28px;
  }
 
  .title {
    font-weight: 600;
    margin-left: 10px;
    font-size: 18px;
    color: #333;
  }
}
 
/* 顶部导航菜单样式 */
.header-nav {
  flex: 1;
  margin: 0 70px;
  border-bottom: none;
 
  :deep(.el-menu-item) {
    height: 60px;
    display: flex;
    align-items: center;
 
    .el-icon {
      margin-right: 5px;
    }
 
    &.is-active {
      color: #1a4b8c;
      border-bottom: 2px solid #1a4b8c;
    }
  }
}
 
.user-info {
  /* 移除下拉组件的默认边框和阴影 */
  :deep(.el-dropdown) {
    outline: none;
    
    .el-dropdown-selfdefine {
      outline: none;
      &:focus {
        outline: none;
      }
    }
  }
 
  .user-name {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    border: 1px solid transparent; /* 添加透明边框防止布局偏移 */
 
    .el-icon {
      margin-right: 5px;
    }
 
    &:hover {
      background-color: #f5f7fa;
      /* 确保悬停时没有边框和阴影 */
      box-shadow: none;
      outline: none;
      border-color: transparent;
    }
 
    /* 修复点击时的焦点样式 */
    &:focus {
      outline: none;
      box-shadow: none;
    }
  }
 
  /* 修复下拉箭头按钮的样式 */
  :deep(.el-icon.el-dropdown__icon)  {
    margin-left: 5px;
    &:hover {
      transform: none;
    }
  }
}

 
/* 内容区居中包装 */
.content-wrapper {
  display: flex;
  justify-content: center;
  width: 100%;
  flex: 1;
  overflow: auto;
  padding: 20px 0;
}
 
/* 主内容区样式 - 始终居中 */
.layout-main {
  width: 100%;
  max-width: 1200px;
  padding: 0 20px;
  background-color: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
 
/* 响应式调整 */
@media (max-width: 768px) {
  .header-content {
    padding: 0 10px;
 
    .title {
      // font-size: 1px;
      display: none;
    }
 
    .header-nav {
      margin: 0 10px;
 
      :deep(.el-menu-item) {
        padding: 0 10px;
        font-size: 14px;
 
        .el-icon {
          display: none;
        }
      }
    }
  }
 
  .content-wrapper {
    padding: 10px 0;
  }
  
  .layout-main {
    padding: 0 10px;
  }
}
</style>